<?php

class product_m_product extends a_base_model_datamapper {

    public function __construct($id=null) {
        $this->table = 'products';
        $this->has_many = array(
        );
        $this->has_one = array(
        );
        
        $this->has_many['text_m_product'] = array(
            'class' => 'text_m_product',
            'join_other_as' => 'text',
            'join_self_as' => 'product'
        );
        $this->has_many['image_m_product'] = array(
            'class' => 'image_m_product',
            'join_other_as' => 'image',
            'join_self_as' => 'product'
        );
        $this->has_one['dimension_m_product'] = array(
            'class' => 'dimension_m_product',
            'join_other_as' => 'dimension',
            'join_self_as' => 'product'
        );

        parent::__construct($id);
    }

    public function get_price(){
        //TO_DO : the price will be calculated based on the price driver..for now its base price
        return round($this->price,2);
    }

    public function get_tax_amount(){
        //@TO_DO : implement after the tax module is done..for now return 0.0
        return 0.0;
    }

    public function get_dimensions()
    {
       $objProdDimension = new dimension_m_product();
       return $objProdDimension->get_by_product_id($this->id);
    }

    public function get_taxes()
    {
      $objProdExemptionsTax = new tax_exemptions_m_product();
      return $objProdExemptionsTax->get_by_product_id($this->id);
    }
    
    public function get_images()
    {
        $objProdImages = new image_m_product();
        return $objProdImages->get_by_product_id($this->id);
    }
    public function get_default_image()
    {
        //@TO_DO : product default image
    }
    public function get_description()
    {
        $lang = service_l_core::get_current_language();
        return $this->text_m_product->where('language_id',$lang->id)->get();
    }

}

?>